/**
 * 495. 提莫攻击
 * https://leetcode.cn/problems/teemo-attacking/description/
 */
class Solution {
    public int findPoisonedDuration(int[] timeSeries, int duration) {
        int n = timeSeries.length;
        int ret = 0;
        for(int i = 0; i < n; i++) {
            if((i == n - 1) || (timeSeries[i + 1] - timeSeries[i] >= duration)) {
                ret += duration;
            } else {
                ret += timeSeries[i + 1] - timeSeries[i];
            }
        }
        return ret;
    }
    public int findPoisonedDuration2(int[] timeSeries, int duration) {
        int n = timeSeries.length;
        int ret = 0;
        for(int i = 1; i < n; i++) {
            int tmp = timeSeries[i] - timeSeries[i - 1];
            if(tmp >= duration) ret += duration;
            else ret+= tmp;
        }
        //最后一次攻击的中毒时间也要算进去
        return ret + duration;
    }
}